<?php
	class htmlControl extends Control{
		//  生成首页；
		function index_html(){
			if($this->html_create("index","index","default.html")){
				$this->success("生成首页成功");
			}
		}
		//  生成栏目列表；
		function list_html(){
			$db = M("category");// 创建新闻模型对象
			$row = $db->findall();// 查找所有记录
			foreach($row as $v){
				if(!isset($v['islisthtml'])){
					continue;
				}
				$_GET['catid']=$v['catid'];
				$html = $this->get_category_html($v);//得到生成静态规则数据
				page::$static_url = __ROOT__.'/'.dirname($html).'/';
				page::$fix='.html';//分页后缀
				$this->html_create('index','list_arc',$html);	
				$totalPage = page::$static_total_page;//总页数
				for($i=1;$i<=$totalPage;$i++){
					$_GET['page']=$i;
					$listHtml = dirname($html).'/'.$i.'.html';
					$this->html_create('index','list_arc',$listHtml);
				}
			}
			$this->success("生成列表页成功");		}
		// 生成内容列表；
		function arc_html(){
			$db = K("newsv");// 创建新闻模型对象
			$row = $db->field("id,archtml,htmldir,isarchtml,addtime")->join("category")->all();// 查找所有记录
			$row = getarcurl($row);
			foreach($row as $v){
				$_GET['id']=$v['id'];
				$html = $this->get_arc_html($v);
				$this->html_create('index','arc',$html);
			}
			$this->success("生成内容页成功");
		}

				//获得列表页url
		private function get_category_html($category){
			return C("htmldir").'/'.$category['htmldir'].'/index.html';
		}
		//获得内容页url
		private function get_arc_html($arc){
			$search=array(
			'{htmldir}',
			'{y}',
			'{m}',
			'{d}',
			'{nid}',
			);
			$date = getdate($arc['addtime']);
			$replace=array(
				$arc['htmldir'],
				$date['year'],
				$date['mon'],
				$date['mday'],
				$arc['id'],
			);
			return  C("htmldir").'/'.str_ireplace($search, $replace, $arc['archtml']);
		}

	}
?>